Skip to content

Use relative-time to render absolute dates#36238

Merged
silverwind merged 10 commits intogo-gitea:mainfrom
silverwind:reltime
Feb 16, 2026
Merged

Use relative-time to render absolute dates#36238
silverwind merged 10 commits intogo-gitea:mainfrom
silverwind:reltime

Conversation

@silverwind
Copy link
Copy Markdown
Member

@silverwind silverwind commented Dec 23, 2025

<relative-time> can render absolute dates when passed threshold="P0Y" and prefix="", so remove the previously used <absolute-date> element in its favor.

Devtest before:

Screenshot 2025-12-23 at 20 22 44

Devtest after:

Screenshot 2025-12-23 at 20 22 49

Repo activity (rendering unchanged):

image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 23, 2025
Comment thread modules/templates/util_date_test.go Outdated
Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have strong objection of using "go-snaps" to update test data automatically.

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 23, 2025
@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Dec 23, 2025

Why object snapshot testing? It's clearly superior than tediously manually writing expected strings. I've given up on a number of PRs because it's too much work to to manually write out expected HTML. Take a look at repos like https://github.com/microsoft/typescript-go, 90% of their tests are snapshot-based. It's a huge DX improvement having the ability to "auto update" tests.

@wxiaoguang
Copy link
Copy Markdown
Contributor

Why object snapshot testing? It's clearly superior than tediously manually writing expected strings. I've given up on a number of PRs because it's too much work to to manually write out expected HTML. Take a look at repos like https://github.com/microsoft/typescript-go, 90% of their tests are snapshot-based. It's a huge DX improvement having the ability to "auto update" tests.

Because many Gitea maintainers are too lazy to write correct tests, not that experienced as typescript-go developers.

But I won't insist, feel free to dismiss my change request if you believe we need it.

@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Dec 23, 2025

I think both regular and snapshot tests have their uses. Let's say I want to add another attribute, I need to manually update 6 assertions vs. running this and be done with it:

UPDATE_SNAPS=true go test -count=1 -run TestDateTime ./modules/templates
UPDATE_SNAPS=true go test -count=1 -run TestTimeSince ./modules/templates

BTW there is nothing preventing you from editing the snapshot assertion string, so the string can be updated either manually (if you prefer), or automatically.

@silverwind silverwind marked this pull request as draft February 12, 2026 10:42
silverwind and others added 2 commits February 12, 2026 19:12
* origin/main: (152 commits)
  Fine tune diff highlighting (go-gitea#36592)
  Add code editor setting dropdowns (go-gitea#36534)
  Update to go 1.26.0 and golangci-lint 2.9.0 (go-gitea#36588)
  Improve diff highlighting (go-gitea#36583)
  Fix markup code block layout (go-gitea#36578)
  Remove striped tables in UI (go-gitea#36509)
  Fix vertical alignment of `.commit-sign-badge` children (go-gitea#36570)
  Fix mirror sync parser and fix mirror messages (go-gitea#36504)
  Update JS and PY deps (go-gitea#36576)
  Add viewer controller for mermaid (zoom, drag) (go-gitea#36557)
  Misc typescript tweaks (go-gitea#36523)
  Use full-file highlighting for diff sections (go-gitea#36561)
  fix(diff): reprocess htmx content after loading more files (go-gitea#36568)
  [skip ci] Updated translations via Crowdin
  Add wrap to runner label list (go-gitea#36565)
  fix: add dnf5 command for Fedora in RPM package instructions (go-gitea#36527)
  Enable pagination on GiteaDownloader.getIssueReactions() (go-gitea#36549)
  Refactor merge conan and container auth preserve actions taskID (go-gitea#36560)
  Fix assignee sidebar links and empty placeholder after go-gitea#32465 refactor (go-gitea#36559)
  Fix various version parsing problems (go-gitea#36553)
  ...
Replace `snaps.MatchInlineSnapshot` calls with `assert.EqualValues` in
date utility tests, removing the github.com/gkampitakis/go-snaps
dependency and its transitive dependencies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@silverwind silverwind marked this pull request as ready for review February 12, 2026 18:16
Copilot AI review requested due to automatic review settings February 12, 2026 18:16
@silverwind
Copy link
Copy Markdown
Member Author

Reverted to static assertions. I guess I will offload such menial task like test assertion updates to agents now, but it's still a waste of agent time when I could have just run a command to update them instantly. But whatever makes you happy.

lunny
lunny previously approved these changes Feb 12, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the project’s custom <absolute-date> web component with @github/relative-time-element configured to render absolute dates (via threshold="P0Y" and prefix=""), aligning date rendering on a single component.

Changes:

  • Remove the <absolute-date> web component (and its unit test) and stop registering it in the frontend build.
  • Update Go template date helpers/tests to emit <relative-time> for “absolute short” date rendering.
  • Update the devtest UI template to demonstrate absolute date rendering via <relative-time>.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
webpack.config.ts Removes absolute-date from the custom-elements allowlist for Vue compilation.
web_src/js/webcomponents/index.ts Stops importing/initializing the absolute-date web component.
web_src/js/webcomponents/absolute-date.ts Deletes the custom absolute date web component implementation.
web_src/js/webcomponents/absolute-date.test.ts Deletes tests for the removed absolute date helper.
templates/devtest/gitea-ui.tmpl Updates devtest examples to use <relative-time> for absolute dates.
modules/templates/util_date.go Switches “date-only” rendering from <absolute-date> to <relative-time> with absolute-date configuration.
modules/templates/util_date_test.go Updates expected HTML strings to match the new <relative-time> output for absolute dates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread templates/devtest/gitea-ui.tmpl Outdated
Comment thread modules/templates/util_date_test.go Outdated
Comment thread modules/templates/util_date.go
silverwind and others added 2 commits February 12, 2026 19:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: silverwind <me@silverwind.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Feb 13, 2026

@wxiaoguang still blocking? go-snaps is removed.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Feb 13, 2026
@wxiaoguang wxiaoguang dismissed lunny’s stale review February 15, 2026 10:49

Suggested by lunny https://discord.com/channels/322538954119184384/323701541297192961/1472491165004726345

And we might could enable the feature that dissmissing all the previous reviews once a new commit pushed after it was approved or rejected.

This PR gets new changes after approval.

@GiteaBot GiteaBot added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 15, 2026
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 16, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 16, 2026
@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 16, 2026
@silverwind silverwind enabled auto-merge (squash) February 16, 2026 09:34
@silverwind silverwind merged commit cfc60b2 into go-gitea:main Feb 16, 2026
24 checks passed
@GiteaBot GiteaBot added this to the 1.26.0 milestone Feb 16, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 16, 2026
@wxiaoguang wxiaoguang deleted the reltime branch February 16, 2026 10:58
silverwind added a commit to Excellencedev/gitea that referenced this pull request Feb 17, 2026
`<relative-time>` can render absolute dates when passed
[`threshold="P0Y"`](https://github.com/github/relative-time-element#threshold-string-default-p30d)
and `prefix=""`, so remove the previously used `<absolute-date>` element
in its favor.

Devtest before:

<img width="324" height="210" alt="Screenshot 2025-12-23 at 20 22 44"
src="https://github.com/user-attachments/assets/cf78e0e7-f480-415f-98d5-09b25f9d5a8b"
/>

Devtest after:

<img width="274" height="184" alt="Screenshot 2025-12-23 at 20 22 49"
src="https://github.com/user-attachments/assets/5e7d25f6-eea1-4a8c-ba71-02b570804b95"
/>

Repo activity (rendering unchanged):

<img width="1023" height="67" alt="image"
src="https://github.com/user-attachments/assets/2c4fd6cb-14ab-43c6-ae4b-f86946b28288"
/>

---------

Signed-off-by: silverwind <me@silverwind.io>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants